class BeautyItemsController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :beauty_item
    @title = '美容项目'
    @beauty_items = BeautyItem.all
  end

  def new
    @beauty_item = BeautyItem.new
  end

  def create
    @beauty_item = BeautyItem.new post_params
    if @beauty_item.save
      redirect_to beauty_items_path
    else
      render :action => 'new'
    end
  end

  def edit
    @beauty_item = BeautyItem.find params[:id]
  end

  def update
    @beauty_item = BeautyItem.find params[:id]
    if @beauty_item.update_attributes post_params
      redirect_to beauty_items_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @beauty_item = BeautyItem.find params[:id]
    @beauty_item.destroy
    redirect_to beauty_items_path
  end

  def post_params
    params.require(:beauty_item).permit(*%w(name amount working_hour))
  end

  private
  def set_menu
    @mainmenu = :base_data
  end
end
